package com.bite.book.controller;

import com.bite.book.constant.Constant;
import com.bite.book.model.UserInfo;
import com.bite.book.service.UserInfoService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserInfoService userInfoService;
    @RequestMapping("/login")
    public boolean login(String name, String password, HttpSession session){
        if(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)){
            return false;
        }
        UserInfo userInfo = userInfoService.cheakpassword(name);
        if(password.equals(userInfo.getPassword())){
            userInfo.setPassword("");
            session.setAttribute(Constant.SESSION_USER_INFO,userInfo);
            return true;
        }
        return false;
    }
}
